<?php

	class SendSMS_SMSBliss extends SendSMS
	{

		const HOST     = 'gate.smsbliss.ru';
		const PORT     = 80;
		const LOGIN    = 'login';
		const PASSWORD = 'password';


		public final function realSend($phone, $text, $sender = null)
		{
			$host     = self::HOST;
			$port     = self::PORT;
			$login    = self::LOGIN;
			$password = self::PASSWORD;
			$sender   = is_null($sender) ? Config_SMS::SENDER : $sender;
			$wapurl   = false;

			//validate and fix phone numbers
			$phone = str_replace(array(' ', '-', '(', ')', '+'), '', $phone);
			if ($phone[0] == '7') {
				$phone[0] = '8';
			}
			if (strlen($phone) != 11) {
				return false;
			}

			$request = "send/" .
				"?phone=" . rawurlencode($phone) .
				"&text=" . rawurlencode($text) .
				($sender ? "&sender=" . rawurlencode($sender) : "") .
				($wapurl ? "&wapurl=" . rawurlencode($wapurl) : "");

			$ch = curl_init("http://{$host}/{$request}");
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
			curl_setopt($ch, CURLOPT_USERPWD, "{$login}:{$password}");
			curl_setopt($ch, CURLOPT_TIMEOUT, Config_SMS::CONNECT_TIMEOUT);
			$response = curl_exec($ch);

			list($msg_id, $status) = explode('=', $response);

			return array(
				'result' => $status == 'accepted' ? 'ok' : 'error',
				'response' => $response,
				'msg_id' => $msg_id,
			);
		}

	}